using System;
using System.Data;
using System.Data.SQLite;

namespace DAL {
    public class SqlHelper {
        private static string connectionString = "datasource=RMS.db";

        public static SQLiteDataReader GetDataReader(SQLiteCommand command) {
            SQLiteConnection connection = new SQLiteConnection(connectionString);
            command.Connection = connection;
            
            connection.Open();
            
            return command.ExecuteReader(CommandBehavior.CloseConnection);
        }

        public static Object GetSingleResult(SQLiteCommand command) {
            using (SQLiteConnection connection = new SQLiteConnection(connectionString)) {
                command.Connection = connection;
                connection.Open();
                
                return command.ExecuteScalar();
            }
        }

        public static int Update(SQLiteCommand command) {
            using (SQLiteConnection connection = new SQLiteConnection(connectionString)) {
                command.Connection = connection;
                connection.Open();
                
                return command.ExecuteNonQuery();
            }
        }

        public static DataTable GetDataTable(SQLiteCommand command) {
            using (SQLiteConnection connection = new SQLiteConnection(connectionString)) {
                command.Connection = connection;
                
                connection.Open();
                
                SQLiteDataAdapter adapter = new SQLiteDataAdapter(command);
                DataTable dataTable = new DataTable();
                adapter.Fill(dataTable);
                
                return dataTable;
            }
        }
    }
}